package io.bluerain.textview;

import android.app.Activity;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.Switch;
import android.widget.ToggleButton;

/**
 * Created by foredawn on 15-9-15.
 * 开关控件基本用法
 */
public class SwitchAndToggleBtnActivity extends Activity {

    Switch switcher;
    ToggleButton togBtn;
    LinearLayout linearLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.switch_toggle_button_test);
        linearLayout = (LinearLayout) findViewById(R.id.layout);
        switcher = (Switch) findViewById(R.id.switcher);
        togBtn = (ToggleButton) findViewById(R.id.tog_btn);

        final CompoundButton.OnCheckedChangeListener listener = new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked)
                    linearLayout.setOrientation(LinearLayout.VERTICAL);
                else
                    linearLayout.setOrientation(LinearLayout.HORIZONTAL);
            }
        };
        switcher.setOnCheckedChangeListener(listener);
        togBtn.setOnCheckedChangeListener(listener);
    }
}
